package com.kordar.admin.modular.sys.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kordar.admin.modular.sys.entity.SettingEntity;
import com.kordar.admin.modular.sys.mapper.SettingMapper;
import com.kordar.admin.modular.sys.service.setting.SettingGenerateTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS("#kordardb")
public class SettingServiceImpl extends ServiceImpl<SettingMapper, SettingEntity> implements SettingService {

    SettingMapper settingMapper;

    @Autowired
    public void setMenuMapper(SettingMapper settingMapper) {
        this.settingMapper = settingMapper;
    }

    @Override
    public List<Object> pidLabels() {
        QueryWrapper<SettingEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("active", 1).orderByDesc("sort");
        List<SettingEntity> result = settingMapper.selectList(queryWrapper);
        SettingGenerateTree tree = new SettingGenerateTree();
        return tree.childTreeMap(result, 0, true);
    }
}
